package com.youyi.yypermissionlibrary.core.os;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.util.Log;

public final class OsHelper {
    private static final String OS_HUAWEI = "HUAWEI";
    private static final String OS_MEIZU = "meizu";
    private static final String OS_NATIVE = Build.MANUFACTURER;
    private static final String OS_OPPO = "Oppo";
    private static final String OS_VIVO = "vivo";
    private static final String OS_XIAOMI = "XiaoMi";

    private OsHelper() {
    }

    public static Intent getIntentNative(Context context) {
        return new Native(context).createIntent();
    }

    public static void startSetting(Activity activity, int i) {
        SettingPage settingPage;
        Intent intent = null;
        try {
            String str = OS_NATIVE;
            if (OS_HUAWEI.equalsIgnoreCase(str)) {
                settingPage = new HuaWei(activity);
            } else if (OS_OPPO.equalsIgnoreCase(str)) {
                settingPage = new Oppo(activity);
            } else if (OS_VIVO.equalsIgnoreCase(str)) {
                settingPage = new Vivo(activity);
            } else if (OS_XIAOMI.equalsIgnoreCase(str)) {
                settingPage = new XiaoMi(activity);
            } else {
                settingPage = OS_MEIZU.equalsIgnoreCase(str) ? new MeiZu(activity) : null;
            }
            intent = settingPage.createIntent();
        } catch (Exception e) {
            Log.e("acp", "OsHelper startSetting " + OS_NATIVE + " " + e.getMessage());
        }
        if (intent == null) {
            intent = getIntentNative(activity);
        }
        try {
            activity.startActivityForResult(intent, i);
        } catch (Exception e2) {
            Log.e("acp", "OsHelper startActivityForResult " + OS_NATIVE + " " + e2.getMessage());
            activity.startActivityForResult(new Intent("android.settings.MANAGE_APPLICATIONS_SETTINGS"), i);
        }
    }

    static boolean isAndroidL() {
        return Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT < 23;
    }

    static boolean isIntentAvailable(Context context, Intent intent) {
        if (intent != null && context.getPackageManager().queryIntentActivities(intent, 65536).size() > 0) {
            return true;
        }
        return false;
    }

    static boolean isActivityExported(Context context, Intent intent) throws PackageManager.NameNotFoundException {
        ActivityInfo activityInfo = context.getPackageManager().getActivityInfo(intent.getComponent(), 65536);
        return activityInfo != null && activityInfo.exported;
    }
}
